package com.uyii.springbootsensitive.aspect;

import com.uyii.springbootsensitive.model.User;
import com.uyii.springbootsensitive.utils.SensitiveDataHandler;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DataMaskingAspect {
    @Around("@annotation(org.springframework.web.bind.annotation.ResponseBody)")
    public Object maskData(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        // 对返回值进行脱敏处理
        if (result instanceof User) {
            User user = (User) result;
            user.setEmail(SensitiveDataHandler.mask(user.getEmail(), "EMAIL"));
        }
        return result;
    }
}